// #include "Thread.h"
// #include <iostream>
// using namespace yhaida;
// void show()
// {
//     std::cout<<"hello world"<<std::endl;
// }
// int main()
// {
//     Thread t(&show,"xhd");
//     t.start();
//     t.join();
//     return 0;
// }

#include "ThreadPool.h"
#include "CountDownLatch.h"
#include <functional>
#include <stdio.h>
using namespace yhaida;
void print()
{
  printf("tid=%d\n", CurrentThread::tid());
}

void printString(const std::string& str)
{
  printf("tid=%d, str=%s\n", CurrentThread::tid(), str.c_str());
}

int main()
{
  ThreadPool pool("MainThreadPool");
  pool.start(5);

  pool.appendTask(print);
  pool.appendTask(print);
  for (int i = 0; i < 100; ++i)
  {
    char buf[32];
    snprintf(buf, sizeof buf, "task %d", i);
    pool.appendTask(std::bind(printString, std::string(buf)));
  }

  CountDownLatch latch(1);
  pool.appendTask(std::bind(&CountDownLatch::downLatch, &latch));
  latch.wait();
  pool.stop();
}


